package com.boot2.core.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;

/**
 * @author zhangweilin
 * @date 2019/3/15 18:30
 * @description: 文件流工具
 */
public class InputStreamUtil {

    public static RandomAccessFile toRandomAccessFile(InputStream is) throws IOException {
        RandomAccessFile raf = new RandomAccessFile(File.createTempFile("isc", "tmp"), "rwd");

        byte[] buffer = new byte[2048];
        int tmp = 0;

        while ((tmp = is.read(buffer)) != -1) {
            raf.write(buffer, 0, tmp);
        }

        raf.seek(0);

        return raf;
    }
}